# 定义自定义异常，继承Exception,一般是满足特定业务场景
class MyCustomError(Exception):

    def __init__(self, *args):
        print("args===", args)
        super().__init__(*args)


try:
    raise MyCustomError("自定义异常类")
except MyCustomError as e:
    print("捕获到的异常=", e)


class DataFormatError(Exception):
    def __init__(self, field, message):
        self.field = field
        self.message = message
        super().__init__(f"{field} 格式错误: {message}")


# 使用示例
try:
    raise DataFormatError("email", "缺少@符号")
except DataFormatError as e:
    print(f"字段: {e.field}, 错误: {e.message}")
